#include "IBackgroundWorker.core.h"
#include "IWorkThread.h"
//========================================================================
//	IBackgroundWorker															
//========================================================================
IBackgroundWorker::IBackgroundWorker()
{
	m_thread = NULL;
	in_progress = false;
}
IBackgroundWorker::~IBackgroundWorker()
{
	if(m_thread){
		m_thread->Delete();
		m_thread = NULL;
	}
}
IWorkThread * IBackgroundWorker::GetThread()
{
	return m_thread;
}
bool IBackgroundWorker::InProgress()
{
	return in_progress;
}
void IBackgroundWorker::SetProgress(bool status)
{
	in_progress = status;
}
bool IBackgroundWorker::Pause()
{
	if(InProgress())
	{
		GetThread()->Pause();
		return true;
	}
	else
		return false;
}
void IBackgroundWorker::Resume()
{
	if(InProgress() && GetThread()->IsPaused())
		GetThread()->Resume();
}
bool IBackgroundWorker::Exec()
{
	wxInitializer wxinit;
    if ( !wxinit.IsOk() )
        return false;
	if(m_thread != NULL)
	{
		if (InProgress())
			return false;
	}
	m_thread = new IWorkThread(this);
	m_thread->Create();
	SetProgress(true);
	m_thread->Run();
	return true;
}

//------------------------------------------------------------------------
